package com.rzdata.poct.web.controller.business;

import com.rzdata.poct.common.annotation.Log;
import com.rzdata.poct.common.annotation.RepeatSubmit;
import com.rzdata.poct.common.core.controller.BaseController;
import com.rzdata.poct.common.core.domain.AjaxResult;
import com.rzdata.poct.common.core.page.TableDataInfo;
import com.rzdata.poct.common.core.validate.AddGroup;
import com.rzdata.poct.common.core.validate.EditGroup;
import com.rzdata.poct.common.core.validate.QueryGroup;
import com.rzdata.poct.common.enums.BusinessType;
import com.rzdata.poct.common.utils.poi.ExcelUtil;
import com.rzdata.poct.system.domain.business.bo.PoctSpaceQualityFileBo;
import com.rzdata.poct.system.domain.business.vo.PoctSpaceQualityFileVo;
import com.rzdata.poct.system.service.IPoctSpaceQualityFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 室间质评文件Controller
 *
 * @author ruoyi
 * @date 2021-09-18
 */
@Validated
@Api(value = "室间质评文件控制器", tags = {"室间质评文件管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/spaceQualityFile")
public class PoctSpaceQualityFileController extends BaseController {

    private final IPoctSpaceQualityFileService iPoctSpaceQualityFileService;

    /**
     * 查询室间质评文件列表
     */
    @ApiOperation("查询室间质评文件列表")
    @PreAuthorize("@ss.hasPermi('system:spaceQualityFile:list')")
    @GetMapping("/list")
    public TableDataInfo<PoctSpaceQualityFileVo> list(@Validated(QueryGroup.class) PoctSpaceQualityFileBo bo) {
        return iPoctSpaceQualityFileService.queryPageList(bo);
    }

    /**
     * 导出室间质评文件列表
     */
    @ApiOperation("导出室间质评文件列表")
    @PreAuthorize("@ss.hasPermi('system:spaceQualityFile:export')")
    @Log(title = "室间质评文件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated PoctSpaceQualityFileBo bo, HttpServletResponse response) {
        List<PoctSpaceQualityFileVo> list = iPoctSpaceQualityFileService.queryList(bo);
        ExcelUtil.exportExcel(list, "室间质评文件", PoctSpaceQualityFileVo.class, response);
    }

    /**
     * 获取室间质评文件详细信息
     */
    @ApiOperation("获取室间质评文件详细信息")
    @PreAuthorize("@ss.hasPermi('system:spaceQualityFile:query')")
    @GetMapping("/{id}")
    public AjaxResult<PoctSpaceQualityFileVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iPoctSpaceQualityFileService.queryById(id));
    }

    /**
     * 新增室间质评文件
     */
    @ApiOperation("新增室间质评文件")
    @PreAuthorize("@ss.hasPermi('system:spaceQualityFile:add')")
    @Log(title = "室间质评文件", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody PoctSpaceQualityFileBo bo) {
        return toAjax(iPoctSpaceQualityFileService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改室间质评文件
     */
    @ApiOperation("修改室间质评文件")
    @PreAuthorize("@ss.hasPermi('system:spaceQualityFile:edit')")
    @Log(title = "室间质评文件", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody PoctSpaceQualityFileBo bo) {
        return toAjax(iPoctSpaceQualityFileService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除室间质评文件
     */
    @ApiOperation("删除室间质评文件")
    @PreAuthorize("@ss.hasPermi('system:spaceQualityFile:remove')")
    @Log(title = "室间质评文件" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPoctSpaceQualityFileService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
